class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> strCnt;
        int result = 0;
        for (int right = 0, left = 0; right < s.size(); ++right) {
            strCnt[s[right]]++;
            while (strCnt[s[right]] > 1) {
                strCnt[s[left++]]--;
            }
            result = max(result, right - left + 1);
        }
        return result;
    }
};